﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Utils
{
    /// <summary>
    /// 验证帮助
    /// </summary>
    public abstract class ExceptionUtils
    {
        /// <summary>
        /// 抛出验证性异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static ValidationException ThrowValidationException(string message)
        {
            throw new ValidationException(message);
        }

        /// <summary>
        /// 数据格式不正确异常
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static FormatException ThrowFormatException(string message)
        {
            throw new FormatException(message);
        }

        /// <summary>
        /// 检查非空
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="argName">参数名称</param>
        public static T CheckNotNull<T>(T value, string argName) where T : class
        {
            if (value == null)
            {
                throw new ArgumentNullException(argName);
            }
            return value;
        }

        /// <summary>
        /// 检查非空和非空白对象
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="argName">参数名称</param>
        /// <returns></returns>
        public static string CheckNotNullOrNotWhiteSpace(string value, string argName)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentNullException(argName);
            }
            return value;
        }


    }
}
